using System;
using System.Collections.Generic;
using System.Web;
using PluginScheduler.Interfaces;
using PluginScheduler.Jobs;

namespace PluginScheduler
{
    public class Scheduler : IScheduler
    {
        private readonly BaseScheduler sched;
        
        public bool IsStarted
        {
            get { return sched.RunningSince.HasValue; }
        }

        public string CurrentlyExecutingJobName
        {
            get { return sched.CurrentlyExecutingJobName; }
        }

        public virtual bool IsShutdown
        {
            get { return sched.IsShutdown; }
        }
        
        public void Clear()
        {
            sched.Clear();
        }

        public Scheduler(HttpContext currentContext)
        {
            this.sched = new BaseScheduler(currentContext);
        }

        public virtual void Start(TimeSpan startInterval)
        {
            sched.Start(startInterval);
        }

        public virtual void Standby()
        {
            sched.Standby();
        }

        public virtual void Shutdown()
        {
            sched.Shutdown(false);
        }

        public virtual void Shutdown(bool waitForJobsToComplete)
        {
            sched.Shutdown(waitForJobsToComplete);
        }

        public void AddJob(IJobDetail jobDetail)
        {
            sched.AddJob(jobDetail);
        }

        public virtual void AddJob(IJobDetail jobDetail, bool replace)
        {
            sched.AddJob(jobDetail, replace);
        }

        public bool DeleteJobs(IList<JobKey> jobKeys)
        {
            return sched.DeleteJobs(jobKeys);
        }

        public virtual bool DeleteJob(JobKey jobKey)
        {
            return sched.DeleteJob(jobKey);
        }

        public bool CheckExists(JobKey jobKey)
        {
            return sched.CheckExists(jobKey);
        }

        public virtual void PauseJob(JobKey jobKey)
        {
            sched.PauseJob(jobKey);
        }
        
        public virtual void ResumeJob(JobKey jobKey)
        {
            sched.ResumeJob(jobKey);
        }

        public virtual void PauseAll()
        {
            sched.PauseAll();
        }

        public virtual void ResumeAll()
        {
            sched.ResumeAll();
        }
    }
}